package cn.gjxblog.controller;

import cn.gjxblog.api.HouseServerFegin;
import cn.gjxblog.common.model.HttpResult;
import cn.gjxblog.model.CommonConstants;
import cn.gjxblog.model.UserContext;
import cn.gjxblog.model.entity.User;
import cn.gjxblog.model.vo.HouseVO;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


/**
 * @author gjx
 * @version v1.0
 * @Description 主页控制器
 * @date 2018/12/7 14:07
 */
@Controller
@Slf4j
public class HomePageController {

    @Autowired
    private HouseServerFegin houseServerFegin;


    @RequestMapping("/index")
    public String index(Model model){
        List<HouseVO> houses =  houseServerFegin.queryLastestHouses().getResult();
        List<HouseVO> result = houseServerFegin.queryGoodHouses().getResult();
        List<HouseVO> houseVOS = queryHotHouses();
        model.addAttribute("hotHouses",houseVOS);

        model.addAttribute("recomHouses", houses);
        model.addAttribute("goodHouses",result);
        return "/homepage/index";
    }


    @RequestMapping("")
    public String index2(){
        return "redirect:/index";
    }

    /**
     * 获取热度排行榜
     * @return
     */
    private List<HouseVO> queryHotHouses() {
        HttpResult<List<HouseVO>> restHouses = houseServerFegin.queryHotHouses(7);
        List<HouseVO> rcHouses =restHouses.getResult();
        return  rcHouses;
    }
}
